var chart;

$(document).ready(function() {
	
	// Count of studentactivity per company
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/get_cat_studentactivity.php',
		success: function(categories){
			$.ajax({
				type:	'POST',
				url:	'ajax/stats/gotsa_company_sa.php',
				success: function(ajaxData){
					chart = new Highcharts.Chart({
						chart: {
							renderTo: 'stat-renderer-1',
							defaultSeriesType: 'column',
							backgroundColor: '#f6f7f8',
							borderColor: '#507aaa',
							borderWidth: 2,
							borderRadius: 0
						},
						title: {
							text: '<strong>Activité universitaire par entreprise</strong>'
						},
						xAxis: {
							categories: jQuery.parseJSON(categories)
						},
						yAxis: {
							title: {
								text: 'Total'
							}
						},
						credits: {
							enabled: false
					    },
					    
						series: jQuery.parseJSON(ajaxData)
					});
				}
			});
		}
	});
	
	// Average duration of a studentactivity per company
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/get_cat_studentactivity.php',
		success: function(categories){
			$.ajax({
				type:	'POST',
				url:	'ajax/stats/avggotsa_company.php',
				success: function(ajaxData){
					chart = new Highcharts.Chart({
						chart: {
							renderTo: 'stat-renderer-2',
							defaultSeriesType: 'column',
							backgroundColor: '#f6f7f8',
							borderColor: '#507aaa',
							borderWidth: 2,
							borderRadius: 0
						},
						title: {
							text: '<strong>Durée moyenne d\'une activité universitaire par entreprise</strong>'
						},
						xAxis: {
							categories: jQuery.parseJSON(categories)
						},
						yAxis: {
							title: {
								text: 'Nombre de jours'
							}
						},
						credits: {
							enabled: false
					    },
						series: jQuery.parseJSON(ajaxData)
					});
				}
			});
		}
	});
	
	// Percentages of activity types
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/activity_type.php',
		success: function(ajaxData){
			chart = new Highcharts.Chart({
				chart: {
					renderTo: 'stat-renderer-5',
					backgroundColor: '#f6f7f8',
					borderColor: '#507aaa',
					borderWidth: 2,
					borderRadius: 0
				},
				title: {
					text: '<strong>Proportions des types d\'activité</strong>'
				},
				tooltip: {
					formatter: function() {
						return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
					}
				},
				plotOptions: {
					pie: {
						allowPointSelect: true,
						cursor: 'pointer',
						dataLabels: {
							enabled: true
						},
						showInLegend: true
					}
				},
				credits: {
					enabled: false
				},
				series: [{
					type: 'pie',
					name: '% des types d\'activité',
					data: jQuery.parseJSON(ajaxData)
				}]
			});
		}
	});
	
	// Number of contact per company
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/contact_company.php',
		success: function(ajaxData){
			chart = new Highcharts.Chart({
				chart: {
					renderTo: 'stat-renderer-4',
					backgroundColor: '#f6f7f8',
					borderColor: '#507aaa',
					borderWidth: 2,
					borderRadius: 0
				},
				title: {
					text: '<strong>Contacts par entreprise</strong>'
				},
				tooltip: {
					formatter: function() {
						return '<b>'+this.point.name+'</b>: '+this.y;
					}
				},
				plotOptions: {
					pie: {
						allowPointSelect: true,
						cursor: 'pointer',
						dataLabels: {
							enabled: true
						},
						showInLegend: true
					}
				},
				credits: {
					enabled: false
				},
				series: [{
					type: 'pie',
					name: 'Contacts par entreprise',
					data: jQuery.parseJSON(ajaxData)
				}]
			});
		}
	});
	
	// Last 12 months studentactivity
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/get_lastmonths.php',
		success: function(categories){
			$.ajax({
				type:	'POST',
				url:	'ajax/stats/gotsa_company_sa_month.php',
				success: function(ajaxData){
					chart = new Highcharts.Chart({
						chart: {
							renderTo: 'stat-renderer-3',
							defaultSeriesType: 'spline',
							backgroundColor: '#f6f7f8',
							borderColor: '#507aaa',
							borderWidth: 2,
							borderRadius: 0
						},
						title: {
							text: '<strong>Activité universitaire des 12 derniers mois</strong>'
						},
						xAxis: {
							categories: jQuery.parseJSON(categories)
						},
						yAxis: {
							title: {
								text: 'Activité (cumul)'
							}
						},
						tooltip: {
							formatter: function() {
								return '<b>'+ this.series.name +'</b><br/>'+this.x+': '+this.y;
							}
						},
						plotOptions: {
							line: {
								dataLabels: {
									enabled: true
								},
								enableMouseTracking: true
							}
						},
						credits: {
							enabled: false
					    },
						series: jQuery.parseJSON(ajaxData)
					});
				}
			});
		}
	});
	
	// Count of remuneration type per company
		$.ajax({
		type:	'POST',
		url:	'ajax/stats/remtype.php',
		success: function(categories){
			$.ajax({
				type:	'POST',
				url:	'ajax/stats/sumremtype_company.php',
				success: function(ajaxData){
					chart = new Highcharts.Chart({
						chart: {
							renderTo: 'stat-renderer-6',
							defaultSeriesType: 'column',
							backgroundColor: '#f6f7f8',
							borderColor: '#507aaa',
							borderWidth: 2,
							borderRadius: 0
						},
						title: {
							text: '<strong>Type de Remuneration par Entreprise</strong>'
						},
						xAxis: {
							categories: jQuery.parseJSON(categories)
						},
						yAxis: {
							title: {
								text: 'Total'
							}
						},
						credits: {
							enabled: false
						},
						series: jQuery.parseJSON(ajaxData)
					});
				}
			});
		}
	});

	// Average Remuneration per company
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/remtype.php',
		success: function(categories){
			$.ajax({
				type:	'POST',
				url:	'ajax/stats/avgrem_company.php',
				success: function(ajaxData){
					chart = new Highcharts.Chart({
						chart: {
							renderTo: 'stat-renderer-7',
							defaultSeriesType: 'column',
							backgroundColor: '#f6f7f8',
							borderColor: '#507aaa',
							borderWidth: 2,
							borderRadius: 0
						},
						title: {
							text: '<strong>Rémunération moyenne</strong>'
						},
						subtitle: {
							text: 'Par type et par entreprise'
						},
						xAxis: {
							categories: jQuery.parseJSON(categories)
						},
						yAxis: {
							title: {
								text: 'Total Par mois'
							}
						},
						plotOptions: {
							column: {
								pointPadding: 0.2,
								borderWidth: 0
							}
						},
						series: jQuery.parseJSON(ajaxData)
					});
				}
			});
		}
	});
});